package org.budo.mongo.jdbc.resultset.impl;

import java.sql.SQLException;
import java.util.Map;

import org.bson.types.ObjectId;
import org.budo.jdbc.driver.resultset.impl.MapArrayResultSet;
import org.budo.support.lang.util.IoUtil;

import lombok.NoArgsConstructor;

/**
 * @author lmw
 */
@NoArgsConstructor
public class MongoMapArrayResultSet extends MapArrayResultSet {
    public MongoMapArrayResultSet(String[] columnNames, Map<?, ?>[] valueArray) {
        super(columnNames, valueArray);
    }

    @Override
    public String getString(int columnIndex) throws SQLException {
        Object value = this.getColumnValueRaw(columnIndex);
        if (null == value) {
            return null;
        }

        // 特殊类型返回值处理
        if (value instanceof ObjectId) {
            return value.toString();
        }

        return IoUtil.toString(value);
    }
}